package com.squareup.picasso;

import android.content.Context;
import android.graphics.Bitmap;
import android.media.ExifInterface;

import com.squareup.picasso.Picasso.LoadedFrom;

import java.io.IOException;
import java.io.InputStream;

final class FileRequestHandler extends ContentStreamRequestHandler {
    FileRequestHandler(Context context) {
        super(context);
    }

    public final boolean canHandleRequest(Request result) {
        return "file".equals(result.uri.getScheme());
    }

    public final Result load(Request request) throws IOException {
        int angle;
        InputStream inputStream = this.getSource(request);
        LoadedFrom loadedFrom = LoadedFrom.DISK;
        switch (new ExifInterface(request.uri.getPath()).getAttributeInt("Orientation", 1)) {
            case 3:
                angle = 180;
                break;
            case 6:
                angle = 90;
                break;
            case 8:
                angle = 270;
                break;
            default:
                angle = 0;
                break;
        }

        return new Result(null, inputStream, loadedFrom, angle);
    }
}

